#pragma once

#include <QSettings>
#include "Const.h"
#include "PictureCtrl.h"

// 游戏
class Game: public QObject {
    Q_OBJECT

    // 难度
    public: enum Difficulty {
        EASY = 9,       // 简单
        MEDIUM = 25,    // 中等
        HARD = 36       // 困难
    };

    // 状态
    public: enum Status {
        END,    // 已结束
        PLAYING // 游戏中
    };

    signals: void UM_GAME_OVER();   // 游戏结束事件

    private: QPixmap* mBitmap;          // 后台缓冲位图
    private: Difficulty mDifficulty;    // 难度
    private: QPainter mDrawer;          // 绘图者
    private: QPoint mEmptyPoint;        // 空点，即没有图的那个点
    private: QWidget* mGameBoard;       // 游戏区域
    private: QImage mImage;             // 图片
    private: bool mPicHasBorder;        // 图片控件是否有边框标志
    private: PictureCtrl* mPictures[Const::MAX_PICTURE_CTRL_COUNT]; // 图片控件数组
    private: Status mStatus;            // 状态

    public: Game(QPixmap*, QWidget*);
    public: virtual ~Game();
    private: void createPictures();
    private: void deletePictures();
    private: void gameOver();
    public: Difficulty getDifficulty();
    public: Status getStatus();
    private: bool isWon();
    public: void movePicture(QWidget*);
    public: bool pictureHasBorder();
    public: void setDifficulty(Difficulty);
    public: void setPicture(const char*);
    public: void setPictureBorder(bool);
    public: void start();
    private: void swapPictures(int, int);
};
